//
//  FPLuckyDrawAlertView.m
//  FootPad
//
//  Created by 张浩 on 2021/5/28.
//  Copyright © 2021 hb_147. All rights reserved.
//

#import "MM_CodeResultAlertView.h"
#import "AppDelegate.h"
#import "MM_CodeResultItemView.h"

@interface MM_CodeResultAlertView ()

@property (nonatomic, strong) UIView *maskView;
@property (nonatomic, strong) UIView *alertView;
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UIButton *fristBtn;
@property (nonatomic, strong) UIButton *lookBtn;

@end

@implementation MM_CodeResultAlertView

- (instancetype)initWithFrame:(CGRect)frame {
    
    if (self = [super initWithFrame:frame]) {
        
        self.frame = CGRectMake(0, 0, ScreenW, ScreenH);
        
        _maskView = [[UIView alloc] init];
        _maskView.backgroundColor = [UIColor colorWithRed:0/255.0 green:0/255.0 blue:0/255.0 alpha:0.5];
        [self addSubview:_maskView];
        
        _alertView = [[UIView alloc] init];
        _alertView.backgroundColor = MM_ColorUtil(@"#ffffff");
        _alertView.layer.cornerRadius = 10;
        _alertView.layer.masksToBounds = YES;
        [self addSubview:_alertView];

        _titleLabel = [Custom_ZHTool uiLabelCreate:@"提示\n您确认对该条数据进行调整吗?" Font:FONT(16) TextColor:[ColorUtil colorWithHexadecimal:@"#000000"]];
        _titleLabel.textAlignment = NSTextAlignmentCenter;
        _titleLabel.numberOfLines = 0;
        _titleLabel.attributedText = [Custom_ZHTool createAttributedStringWithString:@"提示\n您确认对该条数据进行调整吗?" key:@"提示" keyFont:FONT_BOLD(16) keyColor:[ColorUtil colorWithHexadecimal:@"#000000"]];
        [_titleLabel changeLineSpace:10];
        [self.alertView addSubview:_titleLabel];
        
        _fristBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_fristBtn MM_ConfigButtonWithTitle:@"取消" titleFont:FONT(16) titleColor:[ColorUtil colorWithHexadecimal:@"#1F71C4"] bgColor:[ColorUtil colorWithHexadecimal:@"#ffffff"] cornerRadius:10 borderColor:nil borderWidth:0];
        [_fristBtn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
        _fristBtn.tag = 100;
        [self.alertView addSubview:_fristBtn];
        
        _lookBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_lookBtn MM_ConfigButtonWithTitle:@"确定" titleFont:FONT_BOLD(16) titleColor:[ColorUtil colorWithHexadecimal:@"#1F71C4"] bgColor:[ColorUtil colorWithHexadecimal:@"#ffffff"] cornerRadius:10 borderColor:nil borderWidth:0];
        [_lookBtn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
        _lookBtn.tag = 101;
        [self.alertView addSubview:_lookBtn];

        [self setUpViews];
    }
    return self;
}

- (void)setUpViews {
    
    [self.maskView mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.edges.equalTo(self);
    }];
    
    [self.alertView mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.centerX.centerY.equalTo(self);
        make.width.equalTo(280);
        make.height.equalTo(200);
    }];
    
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.equalTo(30);
        make.centerX.equalTo(self.alertView);
    }];
       
    [self.fristBtn mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.bottom.equalTo(self.alertView);
        make.left.equalTo(self.alertView);
        make.width.equalTo(140);
        make.height.equalTo(44);
    }];
    
    [self.lookBtn mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.bottom.equalTo(self.alertView);
        make.left.equalTo(self.fristBtn.mas_right);
        make.width.equalTo(140);
        make.height.equalTo(44);
    }];
    
}

- (void)setNumberArr:(NSArray *)numberArr {
    _numberArr = numberArr;
    
    NSArray *nameArr = @[@"账面数量",@"盘点数量",@"差异数量"];
    
    CGFloat itemW = 280/3.0;
    
    for (int i=0; i<numberArr.count; i++) {
        
        MM_CodeResultItemView *itemView = [[MM_CodeResultItemView alloc] init];
        [itemView setNameStr:nameArr[i] andDescStr:numberArr[i]];
        [self.alertView addSubview:itemView];
        
        [itemView mas_makeConstraints:^(MASConstraintMaker *make) {
           
            make.left.equalTo(itemW * i);
            make.top.equalTo(self.titleLabel.mas_bottom).offset(25);
            make.width.equalTo(itemW);
            make.height.equalTo(50);
        }];
    }
}

- (void)show {
    
    [[UIApplication sharedApplication].keyWindow addSubview:self];
}
- (void)hide {
    [self removeFromSuperview];
}

- (void)btnClick:(UIButton *)button {
    
    NSInteger index = button.tag - 100;
    
    if (self.alertBlock) {
        self.alertBlock();
    }
    
    [self hide];
}

@end
